// PassengerGroupingComparator.java
package com.taxi.analysis.passengerTrip;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * 乘客分组比较器
 * 确保同一乘客的所有行程被分组到同一个Reducer
 */
public class PassengerGroupingComparator extends WritableComparator {

    public PassengerGroupingComparator() {
        super(PassengerTripKey.class, true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        PassengerTripKey key1 = (PassengerTripKey) a;
        PassengerTripKey key2 = (PassengerTripKey) b;

        // 只按乘客ID分组，忽略时间戳和序号
        return key1.getPassengerId().compareTo(key2.getPassengerId());
    }
}
